﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using cebao.DBUtility;//Please add references
namespace cebao.DAL
{
	/// <summary>
	/// 数据访问类:mobileReciveSearchInfo
	/// </summary>
	public partial class mobileReciveSearchInfo
	{
		public mobileReciveSearchInfo()
		{}
		#region  BasicMethod

		/// <summary>
		/// 得到最大ID
		/// </summary>
		public int GetMaxId()
		{
		return DbHelperSQL.GetMaxID("mobileReciveSearchInfoId", "mobileReciveSearchInfo"); 
		}

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(int mobileReciveSearchInfoId)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) from mobileReciveSearchInfo");
			strSql.Append(" where mobileReciveSearchInfoId=@mobileReciveSearchInfoId");
			SqlParameter[] parameters = {
					new SqlParameter("@mobileReciveSearchInfoId", SqlDbType.Int,4)
			};
			parameters[0].Value = mobileReciveSearchInfoId;

			return DbHelperSQL.Exists(strSql.ToString(),parameters);
		}


		/// <summary>
		/// 增加一条数据
		/// </summary>
		public int Add(cebao.Model.mobileReciveSearchInfo model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into mobileReciveSearchInfo(");
			strSql.Append("reciveInfo,isAuto,suid,ruid,reciveTime,mobileSendSearchInfoId)");
			strSql.Append(" values (");
			strSql.Append("@reciveInfo,@isAuto,@suid,@ruid,@reciveTime,@mobileSendSearchInfoId)");
			strSql.Append(";select @@IDENTITY");
			SqlParameter[] parameters = {
					new SqlParameter("@reciveInfo", SqlDbType.Text),
					new SqlParameter("@isAuto", SqlDbType.Bit,1),
					new SqlParameter("@suid", SqlDbType.Int,4),
					new SqlParameter("@ruid", SqlDbType.Int,4),
					new SqlParameter("@reciveTime", SqlDbType.DateTime),
					new SqlParameter("@mobileSendSearchInfoId", SqlDbType.Int,4)};
			parameters[0].Value = model.reciveInfo;
			parameters[1].Value = model.isAuto;
			parameters[2].Value = model.suid;
			parameters[3].Value = model.ruid;
			parameters[4].Value = model.reciveTime;
			parameters[5].Value = model.mobileSendSearchInfoId;

			object obj = DbHelperSQL.GetSingle(strSql.ToString(),parameters);
			if (obj == null)
			{
				return 0;
			}
			else
			{
				return Convert.ToInt32(obj);
			}
		}
		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(cebao.Model.mobileReciveSearchInfo model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update mobileReciveSearchInfo set ");
			strSql.Append("reciveInfo=@reciveInfo,");
			strSql.Append("isAuto=@isAuto,");
			strSql.Append("suid=@suid,");
			strSql.Append("ruid=@ruid,");
			strSql.Append("reciveTime=@reciveTime,");
			strSql.Append("mobileSendSearchInfoId=@mobileSendSearchInfoId");
			strSql.Append(" where mobileReciveSearchInfoId=@mobileReciveSearchInfoId");
			SqlParameter[] parameters = {
					new SqlParameter("@reciveInfo", SqlDbType.Text),
					new SqlParameter("@isAuto", SqlDbType.Bit,1),
					new SqlParameter("@suid", SqlDbType.Int,4),
					new SqlParameter("@ruid", SqlDbType.Int,4),
					new SqlParameter("@reciveTime", SqlDbType.DateTime),
					new SqlParameter("@mobileSendSearchInfoId", SqlDbType.Int,4),
					new SqlParameter("@mobileReciveSearchInfoId", SqlDbType.Int,4)};
			parameters[0].Value = model.reciveInfo;
			parameters[1].Value = model.isAuto;
			parameters[2].Value = model.suid;
			parameters[3].Value = model.ruid;
			parameters[4].Value = model.reciveTime;
			parameters[5].Value = model.mobileSendSearchInfoId;
			parameters[6].Value = model.mobileReciveSearchInfoId;

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(int mobileReciveSearchInfoId)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from mobileReciveSearchInfo ");
			strSql.Append(" where mobileReciveSearchInfoId=@mobileReciveSearchInfoId");
			SqlParameter[] parameters = {
					new SqlParameter("@mobileReciveSearchInfoId", SqlDbType.Int,4)
			};
			parameters[0].Value = mobileReciveSearchInfoId;

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
        public bool DeleteBysid(int mobileSendSearchInfoId)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from mobileReciveSearchInfo ");
            strSql.Append(" where mobileSendSearchInfoId=@mobileSendSearchInfoId");
            SqlParameter[] parameters = {
					new SqlParameter("@mobileSendSearchInfoId", SqlDbType.Int,4)
			};
            parameters[0].Value = mobileSendSearchInfoId;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
		/// <summary>
		/// 批量删除数据
		/// </summary>
		public bool DeleteList(string mobileReciveSearchInfoIdlist )
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from mobileReciveSearchInfo ");
			strSql.Append(" where mobileReciveSearchInfoId in ("+mobileReciveSearchInfoIdlist + ")  ");
			int rows=DbHelperSQL.ExecuteSql(strSql.ToString());
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public cebao.Model.mobileReciveSearchInfo GetModel(int mobileReciveSearchInfoId)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select  top 1 mobileReciveSearchInfoId,reciveInfo,isAuto,suid,ruid,reciveTime,mobileSendSearchInfoId from mobileReciveSearchInfo ");
			strSql.Append(" where mobileReciveSearchInfoId=@mobileReciveSearchInfoId");
			SqlParameter[] parameters = {
					new SqlParameter("@mobileReciveSearchInfoId", SqlDbType.Int,4)
			};
			parameters[0].Value = mobileReciveSearchInfoId;

			cebao.Model.mobileReciveSearchInfo model=new cebao.Model.mobileReciveSearchInfo();
			DataSet ds=DbHelperSQL.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				return DataRowToModel(ds.Tables[0].Rows[0]);
			}
			else
			{
				return null;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public cebao.Model.mobileReciveSearchInfo DataRowToModel(DataRow row)
		{
			cebao.Model.mobileReciveSearchInfo model=new cebao.Model.mobileReciveSearchInfo();
			if (row != null)
			{
				if(row["mobileReciveSearchInfoId"]!=null && row["mobileReciveSearchInfoId"].ToString()!="")
				{
					model.mobileReciveSearchInfoId=int.Parse(row["mobileReciveSearchInfoId"].ToString());
				}
				if(row["reciveInfo"]!=null)
				{
					model.reciveInfo=row["reciveInfo"].ToString();
				}
				if(row["isAuto"]!=null && row["isAuto"].ToString()!="")
				{
					if((row["isAuto"].ToString()=="1")||(row["isAuto"].ToString().ToLower()=="true"))
					{
						model.isAuto=true;
					}
					else
					{
						model.isAuto=false;
					}
				}
				if(row["suid"]!=null && row["suid"].ToString()!="")
				{
					model.suid=int.Parse(row["suid"].ToString());
				}
				if(row["ruid"]!=null && row["ruid"].ToString()!="")
				{
					model.ruid=int.Parse(row["ruid"].ToString());
				}
				if(row["reciveTime"]!=null && row["reciveTime"].ToString()!="")
				{
					model.reciveTime=DateTime.Parse(row["reciveTime"].ToString());
				}
				if(row["mobileSendSearchInfoId"]!=null && row["mobileSendSearchInfoId"].ToString()!="")
				{
					model.mobileSendSearchInfoId=int.Parse(row["mobileSendSearchInfoId"].ToString());
				}
			}
			return model;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select reciveInfo,isAuto,suid,ruid,reciveTime,mobileSendSearchInfoId,utruename ");
			strSql.Append(" FROM VmobileReciveSearchInfo ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
            strSql.Append(" order by reciveTime desc ");
			return DbHelperSQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ");
			if(Top>0)
			{
				strSql.Append(" top "+Top.ToString());
			}
			strSql.Append(" mobileReciveSearchInfoId,reciveInfo,isAuto,suid,ruid,reciveTime,mobileSendSearchInfoId ");
			strSql.Append(" FROM mobileReciveSearchInfo ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			strSql.Append(" order by " + filedOrder);
			return DbHelperSQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获取记录总数
		/// </summary>
		public int GetRecordCount(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) FROM mobileReciveSearchInfo ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			object obj = DbHelperSQL.GetSingle(strSql.ToString());
			if (obj == null)
			{
				return 0;
			}
			else
			{
				return Convert.ToInt32(obj);
			}
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("SELECT * FROM ( ");
			strSql.Append(" SELECT ROW_NUMBER() OVER (");
			if (!string.IsNullOrEmpty(orderby.Trim()))
			{
				strSql.Append("order by T." + orderby );
			}
			else
			{
				strSql.Append("order by T.mobileReciveSearchInfoId desc");
			}
			strSql.Append(")AS Row, T.*  from mobileReciveSearchInfo T ");
			if (!string.IsNullOrEmpty(strWhere.Trim()))
			{
				strSql.Append(" WHERE " + strWhere);
			}
			strSql.Append(" ) TT");
			strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
			return DbHelperSQL.Query(strSql.ToString());
		}

		/*
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		{
			SqlParameter[] parameters = {
					new SqlParameter("@tblName", SqlDbType.VarChar, 255),
					new SqlParameter("@fldName", SqlDbType.VarChar, 255),
					new SqlParameter("@PageSize", SqlDbType.Int),
					new SqlParameter("@PageIndex", SqlDbType.Int),
					new SqlParameter("@IsReCount", SqlDbType.Bit),
					new SqlParameter("@OrderType", SqlDbType.Bit),
					new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
					};
			parameters[0].Value = "mobileReciveSearchInfo";
			parameters[1].Value = "mobileReciveSearchInfoId";
			parameters[2].Value = PageSize;
			parameters[3].Value = PageIndex;
			parameters[4].Value = 0;
			parameters[5].Value = 0;
			parameters[6].Value = strWhere;	
			return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
		}*/

		#endregion  BasicMethod
		#region  ExtensionMethod

		#endregion  ExtensionMethod
	}
}

